<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="page_action.login" %>
<%@ page import="jakarta.servlet.http.Cookie" %>
<%@ page import="object.User" %>

<html>
<head>
    <title>check</title>
</head>
<body>
<%
    String id = request.getParameter("id");
    String upwd = request.getParameter("upwd");
    String identity = request.getParameter("identity");
    String use_type = request.getParameter("use_type");
    if (use_type.equals("注册")) {
        response.sendRedirect("enrol.jsp");
    } else if (use_type.equals("登录")) {
        User user = login.userlogin(id, upwd);
        if (user.getUtype().equals("2") && identity.equals("manager")) {
            response.sendRedirect("manager.jsp");
        } else if (user.getUtype().equals("1") && identity.equals("user")) {
            Cookie cookie=new Cookie("uname",user.getUname());
            Cookie cookie1=new Cookie("uid",String.valueOf(user.getUid()));
            response.addCookie(cookie);
            response.addCookie(cookie1);
            response.sendRedirect("message.jsp");
        } else {
            response.sendRedirect("Error.jsp?message=Invalid credentials");
        }
    } else {
        response.sendRedirect("Error.jsp?message=Invalid credentials");
    }
%>
</body>
</html>